package com.iot.manager.data.models;

import com.google.gson.annotations.SerializedName;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Locale;
import java.util.TimeZone;

public class DeviceData {
    @SerializedName("_id")
    private String id;

    @SerializedName("deviceId")
    private String deviceId;

    @SerializedName("userId")
    private String userId;

    @SerializedName("timestamp")
    private String timestamp;

    @SerializedName("data")
    private Data data;

    @SerializedName("metadata")
    private Metadata metadata;

    @SerializedName("createdAt")
    private String createdAt;

    @SerializedName("updatedAt")
    private String updatedAt;

    @SerializedName("status")
    private String status;

    public static class Data {
        @SerializedName("temperature")
        private Double temperature;

        @SerializedName("humidity")
        private Double humidity;

        public Double getTemperature() {
            return temperature;
        }

        public Double getHumidity() {
            return humidity;
        }
    }

    public static class Metadata {
        @SerializedName("connectionType")
        private String connectionType;
    }

    public Date getTimestamp() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            return sdf.parse(timestamp);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public Double getTemperature() {
        return data != null ? data.getTemperature() : null;
    }

    public Double getHumidity() {
        return data != null ? data.getHumidity() : null;
    }

    public String getConnectionType() {
        return metadata != null ? metadata.connectionType : null;
    }

    public String getStatus() {
        return status != null ? status : "未知";
    }
} 